package com.sgb.kjwl.viewmodel.transport;

import android.app.Application;
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.MutableLiveData;

import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.api.NewAPIManager;
import com.swgk.core.base.api.ICallBack;
import com.sgb.kjwl.model.entity.self.GoodsSelectEntity;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;

import java.util.List;

/**
 * @author: 杨畔
 * @date: 2020/12/29 18:14
 * @Description:
 */
public class CargoPublishCargoInfoViewModel extends AndroidViewModel {
    public MutableLiveData<List<GoodsInfoTypeEntity3>> ldMode = new MutableLiveData<>();
    public MutableLiveData<List<GoodsSelectEntity>> ldPackage = new MutableLiveData<>();

    public CargoPublishCargoInfoViewModel(@NonNull Application application) {
        super(application);
    }

    /**
     * 获取货物类型
     */
    public void getGoodsMode(Context context) {
        DialogHelper.showProgressDialog(context, "数据加载中...");
        NewAPIManager.getInstance().getLogisticsAPI().getGoodsTypeChooseData().enqueue(new ICallBack<BaseEntity<List<GoodsInfoTypeEntity3>>>() {
            @Override
            public void onSuccess(BaseEntity<List<GoodsInfoTypeEntity3>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null && data.getData() != null) {
                    if (!data.getData().isEmpty() && "不限".equals(data.getData().get(0).getName())) {
                        data.getData().remove(0);
                    }
                    ldMode.postValue(data.getData());
                }
            }
        });
    }

    /**
     * 获取包装方式
     */
    public void getPackageMode(Context context) {
        DialogHelper.showProgressDialog(context, "数据加载中...");
        APIManager.getInstance().getDriverAPI().getPackingModes().enqueue(new ICallBack<BaseEntity<List<GoodsSelectEntity>>>() {
            @Override
            public void onSuccess(BaseEntity<List<GoodsSelectEntity>> data) {
                DialogHelper.dismissProgressDialog();
                if (data != null && data.getData() != null) {
                    ldPackage.postValue(data.getData());
                }
            }
        });
    }
}
